#!/bin/sh
echo "Configuration helper for building rrdjtool"
echo ""

echo -n "looking for rrd.h..."
RRD_SOURCE_PATH_f=$(dirname `locate -r src/rrd.h$ 2>/dev/null|head -1`) 2>/dev/null
test -n "$RRD_SOURCE_PATH_f" && 
	echo "ok: $RRD_SOURCE_PATH_f" || echo "not found"
echo "specify rrd source path [$RRD_SOURCE_PATH_f]"
read RRD_SOURCE_PATH
RRD_SOURCE_PATH=${RRD_SOURCE_PATH:-$RRD_SOURCE_PATH_f}
test -d "$RRD_SOURCE_PATH" || exit "directory inesistente"

echo -n "looking for jdk..."
JDK_PATH_f=$(dirname $(dirname `locate -r ^/usr/.*include/jni.h$ 2>/dev/null|head -1`)) 2>/dev/null
test -n "$JDK_PATH_f" && 
	echo "ok: $JDK_PATH_f" || echo "not found"
echo "specify jdk source path [$JDK_PATH_f]"
read JDK_PATH
JDK_PATH=${JDK_PATH:-$JDK_PATH_f}
test -d "$JDK_PATH" || exit "directory inesistente"

echo "configuring Makefile.linux with
JDK_PATH=$JDK_PATH
RRD_SOURCE_PATH=$RRD_SOURCE_PATH
proceed with building?
"
read
sed -e "s|\#JDK_PATH\#|${JDK_PATH}|" -e "s|\#RRD_SOURCE_PATH\#|${RRD_SOURCE_PATH}|" Makefile.linux.src > Makefile.linux

make -f Makefile.linux
